package com.dormitory.manage.controller;

import com.dormitory.manage.pojo.Comment;
import com.dormitory.manage.result.Result;
import com.dormitory.manage.service.CommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Administrator
 * @version 1.0
 * @description CommentController
 * @date 2023/4/21 0021 9:37
 */
@RestController
@RequestMapping("comment")
@CrossOrigin
@Slf4j
public class CommentController {
    @Resource
    private CommentService commentService;

    @GetMapping("getAll")
    public Result getAll(){
        List<Comment> comments = this.commentService.getAll();
        return Result.ok(comments);
    }

    @PostMapping("addComment")
    public Result addComment(@RequestBody Comment comment){
        boolean result = this.commentService.addComment(comment);
        if (result){
            return Result.ok();
        }
        return Result.fail();
    }

    @PutMapping("updateCompleted/{id}")
    public Result updateCompleted(@PathVariable Long id){
        boolean result = this.commentService.updateCompleted(id);
        if (result){
            return Result.ok();
        }
        return Result.fail();
    }

    @DeleteMapping("deleteComment/{id}")
    public Result deleteComment(@PathVariable Long id){
        boolean result = this.commentService.deleteComment(id);
        if (result){
            return Result.ok();
        }
        return Result.fail();
    }

}
